<?php

namespace Admin\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Admin\Controller\IndexController;

class CreateBarcodeDocumentController extends IndexController{
    
    public $userTable;

    public function indexAction() {
        // kiem tra neu chua dang nhap thi quay ve lai trang dang nhap
        if (!$this->getAuthService()->hasIdentity()) {
            return $this->redirect()->toRoute('admin');
        }
        // Neu dang nhap roi thi hien thi len sach sach nguoi dung
        else {
            // Lay thuc the dang nhap dua ra layout
            $this->layout()->identity = $this->getAuthService()->getIdentity();
            // Hien thi dua sanh sach nguoi dung ra view
            $viewModel = new ViewModel;
            $viewModel->setVariables(
                    array(
                        'allUsers' => $this->getUserTable()->fetchAll(),
                    )
            );
            return $viewModel;
        }
    }
public function getUserTable() {
        if (!$this->userTable) {
            $sm = $this->getServiceLocator();
            $this->userTable = $sm->get('Admin\Model\UserTable');
        }
        return $this->userTable;
    }

}
